/* 充电桩应答中心合法用户认证通过信息命令*/
exports.run = (info, core, socket, logger) => {
  let redis = core.getService('redis').getClient();
  const reader = new core.BufferReader(info.data);
  let userIdBuf = reader.read(2),
      cmdIndexBuf = reader.read(2),
      cardNumberBuf = reader.read(16),
      typeBuf = reader.read(1),
      transactionDateBuf = reader.read(8);
  let centerTransactionIdBuf = Buffer.alloc(15),
      bossTransactionIdBuf = Buffer.alloc(20);
  let cardNumber = cardNumberBuf.toString().replace(/\0/g, '').replace(/^0+/g, '');
  logger.info(cardNumber);
  // 通过 redis 获取回 centerTransactionId
  const charging = socket.charging;
  redis.get(`centerTransactionId:${charging}-${cardNumber}`, (err, value) => {
    // redis.set(`currentChargingOrder:${charging}`, JSON.stringify({ cardNumber, numbers: value }), () => {
      logger.info(err, value, `centerTransactionId:${charging}-${cardNumber}`);
      value && centerTransactionIdBuf.write(value);
      socket.sendCommands(0x61, core.concat([
        userIdBuf,
        cmdIndexBuf,
        cardNumberBuf,
        typeBuf,
        transactionDateBuf,
        centerTransactionIdBuf,
        bossTransactionIdBuf
      ]));
      redis.setex(`monitor:${charging}`, [50, true]);
      socket.emit(`0x71-${userIdBuf.toString('hex')}-${cmdIndexBuf.toString('hex')}`, {
        cardNumber, charging
      });
    // })
  });
}
